import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns

movie_genre = pd.read_csv(r"DSProject\csv\movie_genre.csv")
genres_summary = pd.read_csv(r"DSProject\csv\genres_summary.csv")
new_idx = genres_summary.index.rename("genres")
genres_summary.index = new_idx
genres_summary = genres_summary.sort_values("count", ascending=0)
sns.set_theme()
fig, ax = plt.subplots(figsize=(15, 4.5))
sns.barplot(data=genres_summary, x="genres", y="count", hue="genres", ax=ax)
plt.xticks(rotation=90)
plt.title("The relationship between genres and count")
# 保存图形为 PNG 格式
plt.savefig(r"DSProject\View\Figure\genres_count.png", dpi=300, bbox_inches="tight")

# 关闭图形窗口
plt.close()
